﻿using EOS.Framework.Web.Mvc.Rendering;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
// ===============================================================================
// MarkupHelperTest.cs
// EOS Web Framework
// ===============================================================================
// Copyright (c) EOS Development Group. All rights reserved.
// ===============================================================================

namespace EOS.Framework.Web.Mvc.Tests
{
    using System;
    using System.Collections.Generic;
    using EOS.Framework.Web.Mvc.Rendering;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// This is a test class for MarkupHelperTest and is intended
    /// to contain all MarkupHelperTest Unit Tests
    /// </summary>
    [TestClass()]
    public class MarkupHelperTest
    {
        private TestContext testContextInstance;

        /// <summary>
        /// Gets or sets the test context which provides
        /// information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        /// <summary>
        /// A test for FindTags. XML cannot be null.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindTagsNullXmlExceptionTest()
        {
            MarkupHelper.FindTags(null);
        }

        /// <summary>
        /// A test for FindTags. XML be empty.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void FindTagsEmptyXmlExceptionTest()
        {
            MarkupHelper.FindTags(string.Empty);
        }

        /// <summary>
        /// A test for FindTags. XML string cannot contains only blanks.
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void FindTagsBlanksOnlyXmlExceptionTest()
        {
            MarkupHelper.FindTags(" ");
        }

        /// <summary>
        /// A test for FindTags
        /// </summary>
        [TestMethod()]
        public void FindTagsTest()
        {
            string xml = "<test><foo mvc:id=\"id\" /><foo2 mvc:id=\"id2\" /></test>";

            List<string> tags = MarkupHelper.FindTags(xml);
            Assert.AreEqual(2, tags.Count);

            Assert.AreEqual(tags[0], "id");
            Assert.AreEqual(tags[1], "id2");       
        }

        /// <summary>
        /// Finds the ids with input elements.
        /// </summary>
        [TestMethod()]
        public void FindTagsWithInputTest()
        {
            string xml = "<test><foo mvc:id=\"id\" /><input test=\"name\" name=\"id2\" /></test>";

            List<string> tags = MarkupHelper.FindTags(xml);
            Assert.AreEqual(2, tags.Count);

            Assert.AreEqual(tags[0], "id");
            Assert.AreEqual(tags[1], "id2");
        }

        /// <summary>
        /// A test for FindValues
        /// </summary>
        [TestMethod()]
        public void FindValuesTest()
        {
            string text = "#{foo} BLUB BLA #{bar} BUH";

            List<string> values = MarkupHelper.FindValues(text);
            Assert.AreEqual(2, values.Count);

            Assert.AreEqual(values[0], "foo");
            Assert.AreEqual(values[1], "bar");
        }
    }
}
